<?php

class JL_GD2{
	
	function __GET($name){
		return $this->$name;
	}
	function __SET($name,$value){
		$this->$name=$value;
	}
	
	public $image=null;
	
	static function getImage_byFile($imageFile_or_Url,$imageType='PNG'){
		switch (strtoupper($imageType)){
			case 'GIF':
				return imagecreatefromgif($imageFile_or_Url);
			case 'JPG':
			case 'JPE':
			case 'JPEG':
				return imagecreatefromjpeg($imageFile_or_Url);
			case 'PNG':
				return imagecreatefrompng($imageFile_or_Url);
			case 'GD2':
				return imagecreatefromgd2($imageFile_or_Url);
			case 'GD':
				return imagecreatefromgd($imageFile_or_Url);
			default:
				return imagecreatefrompng($imageFile_or_Url);
		}
	}
		
	function __construct($width,$height,$antialias=false){
		$this->image=imagecreatetruecolor($width,$height);
		imageantialias($this->image,$antialias);
	}
	
	function __destruct(){
		$this->destroy();
	}
	
	function setSaw($is_on=true){
		imageantialias($this->image,$is_on);
	}
	
	function buildColor($Red,$Green,$Blue,$alpha=0){
		return imagecolorallocatealpha($this->image,$Red,$Green,$Blue,$alpha);
	}
	
	function getImageW(){
		return imagesx($this->image);
	}
	
	function getImageH(){
		return imagesx($this->image);
	}
	
	function setBG_color($color){
		imagefill($this->image,0,0,$color);
	}
	
	function setStyle($style_color_array){
			imagesetstyle($this->image,$style_color_array);
	}
	
	function setThickness($thickness_px){
		imagesetthickness($this->image,$thickness_px);
	}
	
	function addText($text,$text_size,$x,$y,$is_up=false,$color=null){
		if ($is_up) {
			imagestringup($this->image,$text_size,$x,$y,$text,$color);
		}else {
			imagestring($this->image,$text_size,$x,$y,$text,$color);
		}
	}
	
	function addText_ttf($text,$text_size,$angle,$x,$y,$color,$fontfile){
		imagettftext($this->image,$text_size,$angle,$x,$y,$color,$fontfile,$text);
		
	}
	
	function addPixel($x,$y,$color){
		imagesetpixel($this->image,$x,$y,$color);
	}
	
	function addLine($x_Start,$y_Start,$x_End,$y_End,$color){
		imageline($this->image,$x_Start,$y_Start,$x_End,$y_End,$color);
	}
	
	function addEllipse($cx,$cy,$width,$height,$color){
		imageellipse($this->image,$cx,$cy,$width,$height,$color);
	}
	
	function addRectangle($x_Start,$y_Start,$x_End,$y_End,$color){
		imagerectangle($this->image,$x_Start,$y_Start,$x_End,$y_End,$color);
	}
	
	function addPolygon($points,$color){
		imagepolygon($this->image,$points,intval(count($points)/2),$color);
	}
	
	function setRotate($angle,$color,$ignore_transparent=true){
		$this->image=imagerotate($this->image,$angle,$color,$ignore_transparent);
	}
	
	function show($imageType){
		switch (strtoupper($imageType)){
			case 'GIF':
				Header("Content-type: image/GIF");
				imagegif($this->image);
				break;
			case 'JPG':
			case 'JPE':
			case 'JPEG':
				Header("Content-type: image/JPEG");
				imagejpeg($this->image);
				break;
			case 'PNG':
				Header("Content-type: image/PNG");
				imagepng($this->image);
				break;
			default:
				Header("Content-type: image/PNG");
				imagepng($this->image);
		}
	}
	
	function destroy(){
		if ($this->image!==null) {
			imagedestroy($this->image);
			unset($this->image);
		}
	}

}

?>